package com.nuaa.rag;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetriever;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetrieverOptions;
import com.nuaa.demo.invoke.TestApiKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.DocumentRetriever;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
class LoveAppRagCloudAdvisorConfig {


    @Bean
    public Advisor loveAppRagCloudAdvisor() {
        DashScopeApi dashScopeApi = new DashScopeApi(TestApiKey.API_KEY);
        final String KNOWLEDGE_INDEX = "恋爱大师 V1.0";
        DocumentRetriever documentRetriever = new DashScopeDocumentRetriever(dashScopeApi,
                DashScopeDocumentRetrieverOptions.builder()
                                                 .withIndexName(KNOWLEDGE_INDEX)
                                                 .build());
        return RetrievalAugmentationAdvisor.builder()
                                           .documentRetriever(documentRetriever)
                                           .build();
    }
}
